﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Utils;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ECRMS.WinForm.WinService;
using ECRMS.WinForm.BaseClass.Xml;
using ECRMS.WinForm.BaseClass.Common;


namespace ECRMS.WinForm.BaseClass
{
    /// <summary>
    /// 单例类，是客户端的核心类
    /// </summary>
    public class Core
    {
        private static Core ins;

        //定义主窗体，这样每个control、窗体、module都能调用到主窗体的实例了
        public MainForm CoreMainForm;
        //定义登录窗体
        public LoginForm CoreLoginForm;
        //用户个性化定制
        public XMLReader CoreUserMode;

          //登录前系统启动时读取User.ini文件
        public LangEnum CoreLanguage=LangEnum.中文;

        public static Core getInstance() 
        {
            if (ins == null)
            {
                ins = new Core();
            }
            return ins;
        }


        public Core()
        { 
            
        }

        #region WaitForm功能
        public WaitDialogForm Dlg;

        //此方法到时候用个时候可以重载

        public void CreateWaitDialog(string caption = "", string title = " ")
        {
            Dlg = new WaitDialogForm(caption, title);
        }

        public void CreateWaitDialog(string caption = "", string title = " ", int width = 150, int height = 50, bool isBlock = false, XtraUserControl parentControl = null,XtraForm centerForm = null)
        {
            Dlg = new WaitDialogForm(caption, title ,new System.Drawing.Size(width, height),centerForm==null? ins.CoreMainForm:centerForm);
           
            //可以设置父控件或者祖控件的enable
            if (parentControl != null)
            {
                parentControl.Enabled = isBlock;
            }
        }

        public void CreateWaitDialog(string caption = "", string title = " ", int width = 150, int height = 50, bool isEnable = false, XtraForm parentForm = null,XtraForm centerForm=null)
        {
            Dlg = new WaitDialogForm(caption, title, new System.Drawing.Size(width, height), centerForm == null ? ins.CoreMainForm : centerForm);

            //可以设置父控件或者祖控件的enable
            if (parentForm != null)
            {
                parentForm.Enabled = isEnable;
            }
        }


        public void CloseWaitDialog(XtraUserControl parentControl = null, bool isEnable = true)
        {
            Dlg.Close();
            if (parentControl != null)
            {
                parentControl.Enabled = isEnable;
            }
        }

        public void CloseWaitDialog(XtraForm parentForm = null, bool isEnable = true)
        {
            Dlg.Close();
            if (parentForm != null)
            {
                parentForm.Enabled = isEnable;
            }
        }
        public void CloseWaitDialog()
        {
            Dlg.Close();
        }

        public void SetWaitDialogCaption(string caption)
        {
            if (Dlg != null)
            {
                Dlg.SetCaption(caption);
            }
        }
        #endregion

        #region 语言切换有关功能

        /// <summary>
        /// 此委托可以不加参数，为了后期扩展，先暂时加上
        /// </summary>
        /// <param name="lang"></param>
        public delegate void LanguageChangedHandler(LangEnum lang);

        public event LanguageChangedHandler LangChanged;

        public void ChangeLanguage(LangEnum lang)
        {
            //指定当前的语言
            CoreLanguage = lang;
            try
            {
                //分发委托事件
                LangChanged(lang);
            }
            catch (Exception)
            {
                return;
            }
        }

        #endregion

        #region 登录用户信息类
        public User CoreUser = new User();

        #endregion

        #region 公司相关操作累
     
        public Structure CoreStructure = new Structure();
        public Employee CoreEmployee = new Employee();
        #endregion

        #region 公共类
        public CommonClass CoreCommon = new CommonClass();
        #endregion

        #region 指标相关类
        public IndexOfPlan CoreIndexPlan = new IndexOfPlan();
        public IndexOfEvaluate CoreIndexEvaluate = new IndexOfEvaluate();
        public IndexOfResult CoreIndexResult = new IndexOfResult();
        #endregion

        #region 报表相关类
        
        public ReportOfPlan CoreReportOfPlan = new ReportOfPlan();
        public ReportOfDesign CoreReportOfDesign = new ReportOfDesign();

        #endregion

        #region 公司新闻类
        public Post CorePost = new Post();
        #endregion

    }
}
